<?php

namespace app\service;

use support\UploadFile;

class FileService
{
    function saveFile(UploadFile $file, $path = '')
    {
        $name = date("YmdHis") . '_' . rand(10000, 99999) . '.' . $file->getExtension();

        $path = DIRECTORY_SEPARATOR . date("Ymd") . DIRECTORY_SEPARATOR . $name;
        $savePath = storage_path() . '/upload' . $path;
        $file->move($savePath);
        return [
            'url' => $this->getUrl(['path' => $path]),
        ];
    }

    // $file
    public function getUrl($file)
    {
        return '/public/storage' . $file['path'];
    }
}
